/**
 * @program: LeetCode
 * @description: LeetCode : 377. 组合总和 Ⅳ
 * @author: WXY
 * @create: 2023-01-10 16:20
 * @Version 1.0
 **/
public class Num337_combinationSum4 {
    //如果求组合数就是外层for循环遍历物品，内层for遍历背包。
    //如果求排列数就是外层for遍历背包，内层for循环遍历物品。
    public static int combinationSum4(int[] nums, int target) {
        //dp[i]  凑成i的目标有多少种排列方式
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int i = 0; i <= target; i++) {
            for (int j = 0; j < nums.length; j++) {
                if (i >= nums[j]) {
                    dp[i] += dp[i - nums[j]];
                }
            }
        }
        return dp[target];
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        int i = combinationSum4(arr, 4);
        System.out.println(i);
    }
}
